<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title> - 编辑用户</title>
    <link href="${ctxPath}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"/>
    <link href="${ctxPath}/css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="${ctxPath}/css/animate.css" rel="stylesheet"/>
    <link href="${ctxPath}/css/style.css?v=4.1.0" rel="stylesheet"/>
    <link href="${ctxPath}/css/layui.css" rel="stylesheet" media="all">
    <link href="${ctxPath}/css/plugins/treeview/bootstrap-treeview.css" rel="stylesheet"/>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-6 b-r">
                <form class="form-horizontal" id="userForm">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">用户名：</label>
                        <div class="col-sm-9">
                            <input type="hidden" id="id" name="id" value="${user.id}"/>
                            <input type="text" id="userAcc" name="userAcc" readonly="readonly" value="${user.userAcc}" class="form-control"/>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">密码：</label>
                        <div class="col-sm-9">
                            <input type="password" id="userPsw" name="userPsw" value="${user.userPsw}" placeholder="请输入密码" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">确认密码：</label>
                        <div class="col-sm-9">
                            <input type="password" id="userPsw2" name="userPsw2" value="${user.userPsw}" placeholder="请确认密码" class="form-control"/>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">昵称：</label>
                        <div class="col-sm-9">
                            <input type="text" id="nickName" name="nickName" value="${user.nickName}" placeholder="请输入昵称" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">所属机构：</label>
                        <div class="col-sm-9">
                            <input type="hidden" id="deptId" name="deptId" value="${user.deptId}"/>
                            <input type="text" id="deptName" name="deptName" value="${user.deptName}" readonly="readonly" onclick="hideDeptTree()" placeholder="请选择所属机构" class="form-control"/>
                            <div id="deptTree" style="display: none;"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">角色：</label>
                        <div class="col-sm-9">
                            <input id="roleNames" name="roleNames" type="text" readonly="readonly" value="${user.roleNames}" class="form-control"/>
                            <input id="roleIds" name="roleId" type="hidden" value="${user.roleIds}" />
                            <div class="col-sm-8 m-l-n">
                                <select id="roleIdsTmp" class="form-control" multiple="" onclick="selectRoles(this)"></select>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-9">
                            <input type="hidden" id="avatar" name="avatar" value="${user.avatar}"/>
                            <input type="text" id="description" name="description" value="${user.description}" placeholder="请输入备注" class="form-control"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">头像：</label>
                    <div class="col-sm-9">
                        <div class="layui-upload">
                            <div class="layui-upload-list">
                                @if(tool.isEmpty(user.avatar)){
                                <img class="layui-upload-img " src="${ctxPath}/img/webuploader.png" id="imageShow" />
                                @}else{
                                <img class="layui-upload-img " src="${user.avatar}" id="imageShow" />
                                @}
                                <p id="messText"></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="col-sm-4"></div>
                <div class="col-sm-2">
                    <button type="submit" class="btn btn-w-m btn-success" onclick="saveUser()">提交</button>
                </div>
                <div class="col-sm-2">
                    <button type="button" class="btn btn-w-m btn-danger" onclick="cancel()">取消</button>
                </div>
                <div class="col-sm-4"></div>
            </div>
        </div>
    </div>


    <!-- 全局js -->
    <script src="${ctxPath}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxPath}/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js-->
    <script src="${ctxPath}/js/admin/user/editForm.js"></script>
    <!-- layui upload -->
    <script src="${ctxPath}/js/layui.js" charset="utf-8"></script>

    <!-- jQuery Validation plugin javascript-->
    <script src="${ctxPath}/js/plugins/treeview/bootstrap-treeview.js"></script>
    <script src="${ctxPath}/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${ctxPath}/js/plugins/validate/messages_zh.min.js"></script>
    <script>
        layui.use('upload', function(){
            var upload = layui.upload;
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#imageShow'
                ,url: '/upload/'
                ,data: {type:1}
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#imageShow').attr('src', result); //图片链接（base64）
                    });
                    layer.load(0, {shade: false});
                }
                ,done: function(res){
                    layer.closeAll('loading');
                    //如果上传失败
                    if(res.success){
                        $('#avatar').val(res.data);
                    }else{
                        return layer.msg('上传失败');
                    }
                    //上传成功
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#messText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
    </script>
</body>

</html>
